package com.daikuan.fffkuaiban.adapter;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.daikuan.fffkuaiban.R;
import com.daikuan.fffkuaiban.bmobBean.Creditbean;
import com.daikuan.fffkuaiban.utils.ImageLoader;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by jiming1 on 2017/7/1.
 */
public class XinyongKaListAdapter extends BaseAdapter {
	private Context context;
	private List<Creditbean> xinYongKaBeen;

	public XinyongKaListAdapter(Context context, List<Creditbean> xinYongKaBeen) {
		this.context = context;
		this.xinYongKaBeen = xinYongKaBeen;
	}

	@Override
	public int getCount() {
		return xinYongKaBeen.size();
	}

	@Override
	public Creditbean getItem(int i) {
		return xinYongKaBeen.get(i);
	}

	@Override
	public long getItemId(int i) {
		return 0;
	}

	@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {

		BaseViewHolder viewHolder = null;
		final Creditbean bean = getItem(i);
		if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.item_xinyongka, viewGroup, false);
			viewHolder = new BaseViewHolder(view);
			view.setTag(viewHolder);
		} else {
			viewHolder = (BaseViewHolder) view.getTag();
		}
		ImageLoader.loadImage(context, bean.logo.url, viewHolder.ivImage);
//        ImageLoader.loadImage(context, bean.logo, viewHolder.ivImage);
		viewHolder.tvTitle.setText(bean.title);
		viewHolder.tvInfo.setText(bean.info);
		return view;
	}


	class BaseViewHolder {
		@Bind(R.id.ivImage)
		ImageView ivImage;
		@Bind(R.id.tvTitle)
		TextView tvTitle;
		@Bind(R.id.tvInfo)
		TextView tvInfo;

		public BaseViewHolder(View view) {
			ButterKnife.bind(this, view);
		}
	}


}
